home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 August: Tool Chest / Apple_Developer_Group_August_1996_Tool_Chest.iso / Sample Code / Snippets / Files / Keith's CatSearch / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  2.9 KB  |  113 lines  |  [TEXT/KAHL]

  1. #include "CatSearch.h"
  2.  
  3. #include <stdio.h>
  4.  
  5. main()
  6. {
  7.     short                loopy;
  8.     OSErr                err;
  9.     long                numberFound;
  10.     FSSpec                MPWSpec;
  11.     unsigned long        startTime, endTime;
  12.     
  13.     #define kMaxMatches 100
  14.     FSSpec                pMatchBuffer[kMaxMatches];
  15.  
  16.     if (FALSE)    // Test "Set search criteria and search once, and then search repeatedly"
  17.     {
  18.         printf("Searching for all MPW tools.\n");
  19.         GetDateTime(&startTime);
  20.         err = CatSearch(&numberFound,
  21.                         csVRefNum, (short) -2,
  22.                         csMatchPtr, pMatchBuffer, (long) kMaxMatches,
  23.                         csFInfoFDType, 'MPST',
  24.                         csFInfoFDCreator, 'MPS ',
  25.                         csEndList);
  26.         while ((err == noErr) || (err == eofErr))
  27.         {
  28.             for (loopy = 0; loopy < numberFound; ++loopy)
  29.             {
  30.             //    PtoCstr(pMatchBuffer[loopy].name);
  31.             //    printf("%7ld %s\n", pMatchBuffer[loopy].parID, pMatchBuffer[loopy].name);
  32.             //    CtoPstr((char*) pMatchBuffer[loopy].name);
  33.             }
  34.     
  35.             if (err == noErr)
  36.                 err = CatSearch(&numberFound, csContinue);
  37.             else
  38.                 break;
  39.         }
  40.         GetDateTime(&endTime);
  41.         printf("Search took %ld seconds.\n", endTime - startTime);
  42.     }
  43.  
  44.     if (TRUE)    // Test "Set search criteria, and then search repeatedly"
  45.     {
  46.         printf("Searching for all MPW tools.\n");
  47.         GetDateTime(&startTime);
  48.         err = CatSearch(&numberFound,
  49.                         csVRefNum, (short) -2,
  50.                         csMatchPtr, pMatchBuffer, (long) kMaxMatches,
  51.                         csFInfoFDType, 'MPST',
  52.                         csFInfoFDCreator, 'MPS ',
  53.                         csInitOnly,
  54.                         csEndList);
  55.     
  56.         while (err == noErr)
  57.         {
  58.             err = CatSearch(&numberFound, csContinue);
  59.             if ((err == noErr) || (err == eofErr))
  60.             {
  61.                 for (loopy = 0; loopy < numberFound; ++loopy)
  62.                 {
  63.                 //    PtoCstr(pMatchBuffer[loopy].name);
  64.                 //    printf("%7ld %s\n", pMatchBuffer[loopy].parID, pMatchBuffer[loopy].name);
  65.                 //    CtoPstr((char*) pMatchBuffer[loopy].name);
  66.                 }
  67.             }
  68.         }
  69.         GetDateTime(&endTime);
  70.         printf("Search took %ld seconds.\n", endTime - startTime);
  71.     }
  72.  
  73.     if (TRUE)    // Test "Search for file only within a given subdirectory"
  74.     {
  75.         printf("Searching for all MPW tools in the MPW folder.\n");
  76.         err = CatSearch(&numberFound,
  77.                         csVRefNum, (short) -2,
  78.                         csMatchPtr, &MPWSpec, (long) 1,
  79.                         csFullName, "\pMPW Shell",
  80.                         csFInfoFDType, 'APPL',    // or else it will find my alias!
  81.                         csEndList);
  82.     
  83.         if (numberFound == 0)
  84.             return;
  85.         
  86.         GetDateTime(&startTime);
  87.         err = CatSearch(&numberFound,
  88.                         csVRefNum, MPWSpec.vRefNum,
  89.                         csMatchPtr, pMatchBuffer, (long) kMaxMatches,
  90.                         csFInfoFDType, 'MPST',
  91.                         csFInfoFDCreator, 'MPS ',
  92.                         csSearchInDirectory, MPWSpec.parID,
  93.                         csInitOnly,
  94.                         csEndList);
  95.     
  96.         while (err == noErr)
  97.         {
  98.             err = CatSearch(&numberFound, csContinue);
  99.             if ((err == noErr) || (err == eofErr))
  100.             {
  101.                 for (loopy = 0; loopy < numberFound; ++loopy)
  102.                 {
  103.                 //    PtoCstr(pMatchBuffer[loopy].name);
  104.                 //    printf("%7ld %s\n", pMatchBuffer[loopy].parID, pMatchBuffer[loopy].name);
  105.                 //    CtoPstr((char*) pMatchBuffer[loopy].name);
  106.                 }
  107.             }
  108.         }
  109.         GetDateTime(&endTime);
  110.         printf("Search took %ld seconds.\n", endTime - startTime);
  111.     }
  112. }
  113.